package com.yzc.menu;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yzc.db.SpringDB;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author 22875
 * @description 针对表【t_menu】的数据库操作Service实现
 * @createDate 2024-05-09 15:01:59
 */
@Service
@RequiredArgsConstructor
public class MenuBeanServiceImpl extends ServiceImpl<MenuBeanMapper, MenuBean> {

    final MenuBeanMapper menuBeanMapper;

    final SpringDB springDB;

    public List<MenuBean> loadAll() {
        return menuBeanMapper.loadAll();
    }

    public List<MenuBean> selectInfosByWhere(String name) {
        return menuBeanMapper.selectInfosByWhere(name);
    }

    public List<MenuBean> loadMenuList() {
        return menuBeanMapper.selectList(null);
    }

        public Map updateInfo(MenuBean menuBean) {
            Map map = new HashMap();
            try {
                menuBeanMapper.updateInfo(menuBean);
                map.put("result", "success");
            } catch (Exception e) {
                map.put("result", "error");
                throw new RuntimeException(e);
            }
            return map;
        }

    public Map saveInfo(MenuBean bean) {
        Map map = new HashMap();
        try {
            menuBeanMapper.insert(bean);
            map.put("result", "success");
        } catch (Exception e) {
            map.put("result", "error");
            throw new RuntimeException(e);
        }
        return map;
    }

    public MenuBean getInfoById(String id) {
        return menuBeanMapper.selectById(id);
    }

    public Map deleteInfo(int id) {
        Map map = new HashMap();
        try {
            menuBeanMapper.deleteInfo(id);
            map.put("result", "success");
        } catch (Exception e) {
            map.put("result", "error");
            throw new RuntimeException(e);
        }
        return map;
    }

    public List<MenuBean> loadMenuTree() {
        return menuBeanMapper.loadMenuTree();
    }

    public List<MenuBean> loadMenuTreeByUserid(int userid) {
        return menuBeanMapper.loadMenuTreeByUserid(userid);
    }

}





